package cat.music.ut.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import cat.music.ut.base.BaseRvAdapter
import cat.music.ut.base.CommonRvHolder
import cat.music.ut.bean.AudioInfo
import cat.music.ut.component.click
import cat.music.ut.databinding.ItemQualityBinding

class QualityMusicAdapter(context: Context, data: MutableList<AudioInfo>) :
    BaseRvAdapter<AudioInfo, ItemQualityBinding>(context, data) {
    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): CommonRvHolder<ItemQualityBinding> {
        return CommonRvHolder(
            ItemQualityBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(
        holder: CommonRvHolder<ItemQualityBinding>,
        position: Int,
        vb: ItemQualityBinding,
        bean: AudioInfo
    ) {
        vb.tvDesc.text = "${bean.level} : ${bean.format}"
        vb.tvSize.text = "${bean.size}"
        holder.itemView.click {
            listener?.clickItem(bean)
        }
    }

    var listener: Listener? = null

    interface Listener {
        fun clickItem(data: AudioInfo)
    }
}